home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / DateTimeUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  12.8 KB  |  441 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DateTimeUtils.h
  3.  
  4.      Contains:    International Date and Time Interfaces (previously in TextUtils)
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __DATETIMEUTILS__
  19. #define __DATETIMEUTILS__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27.  
  28.  
  29.  
  30. #if PRAGMA_ONCE
  31. #pragma once
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if PRAGMA_IMPORT
  39. #pragma import on
  40. #endif
  41.  
  42. #if PRAGMA_STRUCT_ALIGN
  43.     #pragma options align=mac68k
  44. #elif PRAGMA_STRUCT_PACKPUSH
  45.     #pragma pack(push, 2)
  46. #elif PRAGMA_STRUCT_PACK
  47.     #pragma pack(2)
  48. #endif
  49.  
  50. /*
  51.  
  52.     Here are the current routine names and the translations to the older forms.
  53.     Please use the newer forms in all new code and migrate the older names out of existing
  54.     code as maintainance permits.
  55.     
  56.     New Name                    Old Name(s)
  57.     
  58.     DateString                    IUDatePString IUDateString 
  59.     InitDateCache
  60.     LongDateString                IULDateString
  61.     LongTimeString                IULTimeString
  62.     StringToDate                String2Date
  63.     StringToTime                                
  64.     TimeString                    IUTimeString IUTimePString
  65.     LongDateToSeconds            LongDate2Secs
  66.     LongSecondsToDate            LongSecs2Date
  67.     DateToSeconds                Date2Secs
  68.     SecondsToDate                Secs2Date
  69. */
  70.  
  71.  
  72. enum {
  73.                                                                 /* Toggle results */
  74.     toggleUndefined                = 0,
  75.     toggleOK                    = 1,
  76.     toggleBadField                = 2,
  77.     toggleBadDelta                = 3,
  78.     toggleBadChar                = 4,
  79.     toggleUnknown                = 5,
  80.     toggleBadNum                = 6,
  81.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  82.     toggleErr3                    = 7,
  83.     toggleErr4                    = 8,
  84.     toggleErr5                    = 9
  85. };
  86.  
  87.  
  88. enum {
  89.                                                                 /* Date equates */
  90.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  91.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  92.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  93.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  94.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  95.     validDateFields                = -1,
  96.     maxDateField                = 10
  97. };
  98.  
  99.  
  100. enum {
  101.     eraMask                        = 0x0001,
  102.     yearMask                    = 0x0002,
  103.     monthMask                    = 0x0004,
  104.     dayMask                        = 0x0008,
  105.     hourMask                    = 0x0010,
  106.     minuteMask                    = 0x0020,
  107.     secondMask                    = 0x0040,
  108.     dayOfWeekMask                = 0x0080,
  109.     dayOfYearMask                = 0x0100,
  110.     weekOfYearMask                = 0x0200,
  111.     pmMask                        = 0x0400,
  112.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  113. };
  114.  
  115.  
  116. enum {
  117.     eraField                    = 0,
  118.     yearField                    = 1,
  119.     monthField                    = 2,
  120.     dayField                    = 3,
  121.     hourField                    = 4,
  122.     minuteField                    = 5,
  123.     secondField                    = 6,
  124.     dayOfWeekField                = 7,
  125.     dayOfYearField                = 8,
  126.     weekOfYearField                = 9,
  127.     pmField                        = 10,
  128.     res1Field                    = 11,
  129.     res2Field                    = 12,
  130.     res3Field                    = 13
  131. };
  132.  
  133. typedef SignedByte                         LongDateField;
  134.  
  135. enum {
  136.     shortDate                    = 0,
  137.     longDate                    = 1,
  138.     abbrevDate                    = 2
  139. };
  140.  
  141. typedef SInt8                             DateForm;
  142.  
  143. enum {
  144.                                                                 /* StringToDate status values */
  145.     fatalDateTime                = 0x8000,                        /* StringToDate and String2Time mask to a fatal error */
  146.     longDateFound                = 1,                            /* StringToDate mask to long date found */
  147.     leftOverChars                = 2,                            /* StringToDate & Time mask to warn of left over characters */
  148.     sepNotIntlSep                = 4,                            /* StringToDate & Time mask to warn of non-standard separators */
  149.     fieldOrderNotIntl            = 8,                            /* StringToDate & Time mask to warn of non-standard field order */
  150.     extraneousStrings            = 16,                            /* StringToDate & Time mask to warn of unparsable strings in text */
  151.     tooManySeps                    = 32,                            /* StringToDate & Time mask to warn of too many separators */
  152.     sepNotConsistent            = 64,                            /* StringToDate & Time mask to warn of inconsistent separators */
  153.     tokenErr                    = 0x8100,                        /* StringToDate & Time mask for 'tokenizer err encountered' */
  154.     cantReadUtilities            = 0x8200,
  155.     dateTimeNotFound            = 0x8400,
  156.     dateTimeInvalid                = 0x8800
  157. };
  158.  
  159. typedef short                             StringToDateStatus;
  160. typedef short                             String2DateStatus;
  161. struct DateCacheRecord {
  162.     short                             hidden[256];                /* only for temporary use */
  163. };
  164. typedef struct DateCacheRecord DateCacheRecord;
  165.  
  166. typedef DateCacheRecord *                DateCachePtr;
  167. struct DateTimeRec {
  168.     short                             year;
  169.     short                             month;
  170.     short                             day;
  171.     short                             hour;
  172.     short                             minute;
  173.     short                             second;
  174.     short                             dayOfWeek;
  175. };
  176. typedef struct DateTimeRec DateTimeRec;
  177.  
  178. typedef SInt64                             LongDateTime;
  179. union LongDateCvt {
  180.     SInt64                             c;
  181.     struct {
  182.         UInt32                             lHigh;
  183.         UInt32                             lLow;
  184.     }                                 hl;
  185. };
  186. typedef union LongDateCvt LongDateCvt;
  187.  
  188. union LongDateRec {
  189.     struct {
  190.         short                             era;
  191.         short                             year;
  192.         short                             month;
  193.         short                             day;
  194.         short                             hour;
  195.         short                             minute;
  196.         short                             second;
  197.         short                             dayOfWeek;
  198.         short                             dayOfYear;
  199.         short                             weekOfYear;
  200.         short                             pm;
  201.         short                             res1;
  202.         short                             res2;
  203.         short                             res3;
  204.     }                                 ld;
  205.     short                             list[14];                    /*Index by LongDateField!*/
  206.     struct {
  207.         short                             eraAlt;
  208.         DateTimeRec                     oldDate;
  209.     }                                 od;
  210. };
  211. typedef union LongDateRec LongDateRec;
  212.  
  213. typedef SInt8                             DateDelta;
  214. struct TogglePB {
  215.     long                             togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  216.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  217.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  218.     long                             reserved[4];
  219. };
  220. typedef struct TogglePB TogglePB;
  221.  
  222. typedef short                             ToggleResults;
  223. /*
  224.  **************************************************************************************
  225.  *
  226.  * The following functions are new names that work on 68k and PowerPC
  227.  *
  228.  **************************************************************************************
  229. */
  230.  
  231. EXTERN_API( OSErr )
  232. InitDateCache                    (DateCachePtr             theCache)                            FOURWORDINLINE(0x2F3C, 0x8204, 0xFFF8, 0xA8B5);
  233.  
  234. EXTERN_API( StringToDateStatus )
  235. StringToDate                    (Ptr                     textPtr,
  236.                                  long                     textLen,
  237.                                  DateCachePtr             theCache,
  238.                                  long *                    lengthUsed,
  239.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF6, 0xA8B5);
  240.  
  241. EXTERN_API( StringToDateStatus )
  242. StringToTime                    (Ptr                     textPtr,
  243.                                  long                     textLen,
  244.                                  DateCachePtr             theCache,
  245.                                  long *                    lengthUsed,
  246.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF4, 0xA8B5);
  247.  
  248. EXTERN_API( void )
  249. IUDateString                    (long                     dateTime,
  250.                                  DateForm                 longFlag,
  251.                                  Str255                 result)                                TWOWORDINLINE(0x4267, 0xA9ED);
  252.  
  253. EXTERN_API( void )
  254. IUTimeString                    (long                     dateTime,
  255.                                  Boolean                 wantSeconds,
  256.                                  Str255                 result)                                THREEWORDINLINE(0x3F3C, 0x0002, 0xA9ED);
  257.  
  258. EXTERN_API( void )
  259. IUDatePString                    (long                     dateTime,
  260.                                  DateForm                 longFlag,
  261.                                  Str255                 result,
  262.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  263.  
  264. EXTERN_API( void )
  265. IUTimePString                    (long                     dateTime,
  266.                                  Boolean                 wantSeconds,
  267.                                  Str255                 result,
  268.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  269.  
  270. EXTERN_API( void )
  271. IULDateString                    (LongDateTime *            dateTime,
  272.                                  DateForm                 longFlag,
  273.                                  Str255                 result,
  274.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  275.  
  276. EXTERN_API( void )
  277. IULTimeString                    (LongDateTime *            dateTime,
  278.                                  Boolean                 wantSeconds,
  279.                                  Str255                 result,
  280.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  281.  
  282.  
  283. EXTERN_API( void )
  284. LongDateToSeconds                (const LongDateRec *    lDate,
  285.                                  LongDateTime *            lSecs)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  286.  
  287. EXTERN_API( void )
  288. LongSecondsToDate                (const LongDateTime *    lSecs,
  289.                                  LongDateRec *            lDate)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  290.  
  291. EXTERN_API( ToggleResults )
  292. ToggleDate                        (LongDateTime *            lSecs,
  293.                                  LongDateField             field,
  294.                                  DateDelta                 delta,
  295.                                  short                     ch,
  296.                                  const TogglePB *        params)                                FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  297.  
  298. EXTERN_API( short )
  299. ValidDate                        (const LongDateRec *    vDate,
  300.                                  long                     flags,
  301.                                  LongDateTime *            newSecs)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  302.  
  303.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  304.                                                                                             #pragma parameter __D0 ReadDateTime(__A0)
  305.                                                                                             #endif
  306. EXTERN_API( OSErr )
  307. ReadDateTime                    (unsigned long *        time)                                ONEWORDINLINE(0xA039);
  308.  
  309.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  310.                                                                                             #pragma parameter GetDateTime(__A0)
  311.                                                                                             #endif
  312. EXTERN_API( void )
  313. GetDateTime                        (unsigned long *        secs)                                TWOWORDINLINE(0x20B8, 0x020C);
  314.  
  315.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  316.                                                                                             #pragma parameter __D0 SetDateTime(__D0)
  317.                                                                                             #endif
  318. EXTERN_API( OSErr )
  319. SetDateTime                        (unsigned long             time)                                ONEWORDINLINE(0xA03A);
  320.  
  321.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  322.                                                                                             #pragma parameter SetTime(__A0)
  323.                                                                                             #endif
  324. EXTERN_API( void )
  325. SetTime                            (const DateTimeRec *    d)                                    TWOWORDINLINE(0xA9C7, 0xA03A);
  326.  
  327.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  328.                                                                                             #pragma parameter GetTime(__A0)
  329.                                                                                             #endif
  330. EXTERN_API( void )
  331. GetTime                            (DateTimeRec *            d)                                    THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  332.  
  333. EXTERN_API( void )
  334. DateToSeconds                    (const DateTimeRec *    d,
  335.                                  unsigned long *        secs);
  336.  
  337.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  338.                                                                                             #pragma parameter SecondsToDate(__D0, __A0)
  339.                                                                                             #endif
  340. EXTERN_API( void )
  341. SecondsToDate                    (unsigned long             secs,
  342.                                  DateTimeRec *            d)                                    ONEWORDINLINE(0xA9C6);
  343.  
  344. /*
  345.  **************************************************************************************
  346.  *
  347.  * The following are macros which map new names to the names exported by InterfaceLib
  348.  *
  349.  **************************************************************************************
  350. */
  351. #define DateString(dateTime, longFlag, result, intlHandle) \
  352.          IUDatePString( dateTime, longFlag, result, intlHandle)
  353. #define TimeString(dateTime, wantSeconds, result, intlHandle) \
  354.          IUTimePString(dateTime, wantSeconds, result, intlHandle)
  355. #define LongDateString(dateTime, longFlag, result, intlHandle) \
  356.          IULDateString(dateTime, longFlag, result, intlHandle)
  357. #define LongTimeString(dateTime, wantSeconds, result, intlHandle) \
  358.          IULTimeString(dateTime, wantSeconds, result, intlHandle)
  359.  
  360. /*
  361.  **************************************************************************************
  362.  *
  363.  * The following are macros which map old names to the names exported by InterfaceLib
  364.  *
  365.  **************************************************************************************
  366. */
  367. #if OLDROUTINENAMES
  368. #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  369.          StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
  370. #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  371.          StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
  372. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  373. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  374. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  375. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  376. #if CGLUESUPPORTED
  377. EXTERN_API_C( void )
  378. iudatestring                    (long                     dateTime,
  379.                                  DateForm                 longFlag,
  380.                                  char *                    result);
  381.  
  382. EXTERN_API_C( void )
  383. iudatepstring                    (long                     dateTime,
  384.                                  DateForm                 longFlag,
  385.                                  char *                    result,
  386.                                  Handle                 intlHandle);
  387.  
  388. EXTERN_API_C( void )
  389. iutimestring                    (long                     dateTime,
  390.                                  Boolean                 wantSeconds,
  391.                                  char *                    result);
  392.  
  393. EXTERN_API_C( void )
  394. iutimepstring                    (long                     dateTime,
  395.                                  Boolean                 wantSeconds,
  396.                                  char *                    result,
  397.                                  Handle                 intlHandle);
  398.  
  399. EXTERN_API_C( void )
  400. iuldatestring                    (LongDateTime *            dateTime,
  401.                                  DateForm                 longFlag,
  402.                                  char *                    result,
  403.                                  Handle                 intlHandle);
  404.  
  405. EXTERN_API_C( void )
  406. iultimestring                    (LongDateTime *            dateTime,
  407.                                  Boolean                 wantSeconds,
  408.                                  char *                    result,
  409.                                  Handle                 intlHandle);
  410.  
  411. #else
  412. #endif  /* CGLUESUPPORTED */
  413.  
  414. #endif  /* OLDROUTINENAMES */
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421. #if PRAGMA_STRUCT_ALIGN
  422.     #pragma options align=reset
  423. #elif PRAGMA_STRUCT_PACKPUSH
  424.     #pragma pack(pop)
  425. #elif PRAGMA_STRUCT_PACK
  426.     #pragma pack()
  427. #endif
  428.  
  429. #ifdef PRAGMA_IMPORT_OFF
  430. #pragma import off
  431. #elif PRAGMA_IMPORT
  432. #pragma import reset
  433. #endif
  434.  
  435. #ifdef __cplusplus
  436. }
  437. #endif
  438.  
  439. #endif /* __DATETIMEUTILS__ */
  440.  
  441.